﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Security.Cryptography;
using Microsoft.AspNetCore.Cryptography.KeyDerivation;
using Work.Models;

namespace Work.util
{
	public class PasswordHasher
	{
		public static byte[] salt()
		{
			byte[] salt = new byte[128 / 8];
			using (var rng = RandomNumberGenerator.Create())
			{
				rng.GetBytes(salt);
			}
			Console.WriteLine($"Salt: {Convert.ToBase64String(salt)}");
			return salt;
		}
		public static string  Hashed(string password,byte[] salt)
		{ 
			string hashed = Convert.ToBase64String(KeyDerivation.Pbkdf2(
				password: password,
				salt: salt,
				prf: KeyDerivationPrf.HMACSHA1,
				iterationCount: 10000,
				numBytesRequested: 256 / 8));
			Console.WriteLine($"Hashed: {hashed}");
			return hashed;
		}
	}
}
